home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / gnome-1.0 / gtk-xmhtml / miniparse.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-20  |  12.3 KB  |  398 lines

  1. /*****
  2. * miniparse.h : required header file when compiling the parser standalone.
  3. *
  4. * This file Version    $Revision: 1.3 $
  5. *
  6. * Creation date:        Wed Mar 19 17:26:15 GMT+0100 1997
  7. * Last modification:     $Date: 1998/02/12 03:09:33 $
  8. * By:                    $Author: unammx $
  9. * Current State:        $State: Exp $
  10. *
  11. * Author:                newt
  12. *
  13. * Copyright (C) 1994-1997 by Ripley Software Development 
  14. * All Rights Reserved
  15. *
  16. * This file is part of the XmHTML Widget Library.
  17. *
  18. * This library is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU Library General Public
  20. * License as published by the Free Software Foundation; either
  21. * version 2 of the License, or (at your option) any later version.
  22. *
  23. * This library is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  26. * Library General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Library General Public
  29. * License along with this library; if not, write to the Free
  30. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. *
  32. *****/
  33. /*****
  34. * $Source: /cvs/gnome/gnome-libs/gtk-xmhtml/Attic/miniparse.h,v $
  35. *****/
  36. /*****
  37. * ChangeLog 
  38. * $Log: miniparse.h,v $
  39. * Revision 1.3  1998/02/12 03:09:33  unammx
  40. * Merge to Koen's XmHTML 1.1.2 + following fixes:
  41. *
  42. * Wed Feb 11 20:27:19 1998  Miguel de Icaza  <miguel@nuclecu.unam.mx>
  43. *
  44. *     * gtk-forms.c (freeForm): gtk_destroy_widget is no longer needed
  45. *     with the refcounting changes.
  46. *
  47. *     * gtk-xmhtml.c (gtk_xmhtml_remove): Only god knows why I was
  48. *     adding the just removed widget.
  49. *
  50. * Revision 1.2  1997/12/29 22:16:32  unammx
  51. * This version does:
  52. *
  53. *    - Sync with Koen to version Beta 1.1.2c of the XmHTML widget.
  54. *      Includes various table fixes.
  55. *
  56. *    - Callbacks are now properly checked for the Gtk edition (ie,
  57. *      signals).
  58. *
  59. * Revision 1.1  1997/12/25 01:34:13  unammx
  60. * Good news for the day:
  61. *
  62. *    I have upgraded our XmHTML sources to XmHTML 1.1.1.
  63. *
  64. *    This basically means that we got table support :-)
  65. *
  66. * Still left to do:
  67. *
  68. *    - Set/Get gtk interface for all of the toys in the widget.
  69. *    - Frame support is broken, dunno why.
  70. *    - Form support (ie adding widgets to it)
  71. *
  72. * Miguel.
  73. *
  74. * Revision 1.6  1997/10/23 00:30:39  newt
  75. * XmHTML Beta 1.1.0 release
  76. *
  77. * Revision 1.5  1997/08/30 02:04:25  newt
  78. * _XmHTMLWarning proto changes.
  79. *
  80. * Revision 1.3  1997/05/28 01:56:39  newt
  81. * Added my_strdup.
  82. *
  83. * Revision 1.2  1997/04/29 14:31:41  newt
  84. * Removed unused structures.
  85. *
  86. * Revision 1.1  1997/03/20 08:01:55  newt
  87. * Initial Revision
  88. *
  89. *****/ 
  90. #ifndef _miniparse_h_
  91. #define _miniparse_h_
  92.  
  93. #ifndef MINIPARSE
  94. #define MINIPARSE 1
  95. #endif
  96.  
  97. #include <sys/time.h>
  98. #include <unistd.h>
  99.  
  100. #ifdef __STDC__
  101. #include <stdarg.h>
  102. #else
  103. #include <varargs.h>
  104. #endif
  105.  
  106. #include <errno.h>    /* perror */
  107.  
  108.  
  109. /* required typedefs */
  110. typedef char* String;
  111. typedef unsigned char Byte;
  112. typedef unsigned char Boolean;
  113. typedef unsigned short Dimension;
  114. typedef unsigned char* Widget;
  115. typedef Widget XmHTMLWidget;
  116.  
  117. /* Set to False if you don't want any warnings being issued */
  118. extern Boolean parser_warnings;
  119.  
  120. /* Running count of encountered errors */
  121. extern int parser_errors;
  122.  
  123. /* Count of HTML segments in the input text */
  124. extern int parsed_object_count;
  125.  
  126. /* Count of text segments in the input text */
  127. extern int parsed_text_object_count;
  128.  
  129. /* Set to False if you want the parser to be a bit more lenient */
  130. extern Boolean parser_strict_checking;
  131.  
  132. /* Set to True if you want to see debug output */
  133. extern Boolean parser_debug;
  134.  
  135. /* Set to True if you want to get timings from the parser tree verification */
  136. extern Boolean parser_verification_timings;
  137.  
  138. /* we always set debug flag in here */
  139. #ifndef DEBUG
  140. #define DEBUG    1
  141. #endif
  142.  
  143. #ifndef True
  144. #  define True 1
  145. #  define False 0
  146. #endif
  147.  
  148. /*****
  149. * HTML Elements internal id's
  150. * This list is alphabetically sorted to speed up the searching process.
  151. * DO NOT MODIFY
  152. *****/
  153. typedef enum{
  154. HT_DOCTYPE, HT_A, HT_ADDRESS, HT_APPLET, HT_AREA, HT_B, HT_BASE, HT_BASEFONT, 
  155. HT_BIG, HT_BLOCKQUOTE, HT_BODY, HT_BR, HT_CAPTION, HT_CENTER, HT_CITE, HT_CODE,
  156. HT_DD, HT_DFN, HT_DIR, HT_DIV, HT_DL, HT_DT, HT_EM, HT_FONT, HT_FORM, HT_FRAME,
  157. HT_FRAMESET, HT_H1, HT_H2, HT_H3, HT_H4, HT_H5, HT_H6, HT_HEAD, HT_HR, HT_HTML,
  158. HT_I, HT_IMG, HT_INPUT, HT_ISINDEX, HT_KBD, HT_LI, HT_LINK, HT_MAP, HT_MENU,
  159. HT_META, HT_NOFRAMES, HT_OL, HT_OPTION, HT_P, HT_PARAM, HT_PRE, HT_SAMP,
  160. HT_SCRIPT, HT_SELECT, HT_SMALL, HT_STRIKE, HT_STRONG, HT_STYLE, HT_SUB,
  161. HT_SUP, HT_TAB, HT_TABLE, HT_TD, HT_TEXTAREA, HT_TH, HT_TITLE,
  162. HT_TR, HT_TT, HT_U, HT_UL, HT_VAR, HT_ZTEXT
  163. }htmlEnum;
  164.  
  165. /***** 
  166. * and corresponding name table, defined in parse.c
  167. *****/
  168. extern String html_tokens[];
  169.  
  170. /* elements for which a closing counterpart is optional */
  171. #define OPTIONAL_CLOSURE(id) ((id) == HT_DD || (id) == HT_DT || \
  172.     (id) == HT_LI || (id) == HT_P || (id) == HT_OPTION || (id) == HT_TD || \
  173.     (id) == HT_TH || (id) == HT_TR)
  174.  
  175. /* physical/logical markup elements */
  176. #define IS_MARKUP(id) ((id) == HT_TT || (id) == HT_I || (id) == HT_B || \
  177.     (id) == HT_U || (id) == HT_STRIKE || (id) == HT_BIG || (id) == HT_SMALL || \
  178.     (id) == HT_SUB || (id) == HT_SUP || (id) == HT_EM || (id) == HT_STRONG || \
  179.     (id) == HT_DFN || (id) == HT_CODE || (id) == HT_SAMP || (id) == HT_KBD || \
  180.     (id) == HT_VAR || (id) == HT_CITE || (id) == HT_FONT)
  181.  
  182. /* text containers */
  183. #define IS_CONTAINER(id) ((id) == HT_BODY || (id) == HT_DIV || \
  184.     (id) == HT_CENTER || (id) == HT_BLOCKQUOTE || (id) == HT_FORM || \
  185.     (id) == HT_TH || (id) == HT_TD || (id) == HT_DD || (id) == HT_LI || \
  186.     (id) == HT_NOFRAMES)
  187.  
  188. /* all elements that may be nested */
  189. #define NESTED_ELEMENT(id) (IS_MARKUP(id) || (id) == HT_APPLET || \
  190.     (id) == HT_BLOCKQUOTE || (id) == HT_DIV || (id) == HT_CENTER || \
  191.     (id) == HT_FRAMESET)
  192.  
  193. /* other elements */
  194. #define IS_MISC(id) ((id) == HT_P || (id) == HT_H1 || (id) == HT_H2 || \
  195.     (id) == HT_H3 || (id) == HT_H4 || (id) == HT_H5 || (id) == HT_H6 || \
  196.     (id) == HT_PRE || (id) == HT_ADDRESS || (id) == HT_APPLET || \
  197.     (id) == HT_CAPTION || (id) == HT_A || (id) == HT_DT)
  198.  
  199.  
  200. /*****
  201. * possible error codes for XmNparserCallback
  202. *****/
  203. typedef enum{
  204.     HTML_UNKNOWN_ELEMENT = 1,    /* unknown HTML element */
  205.     HTML_BAD,                    /* very badly placed element */
  206.     HTML_OPEN_BLOCK,            /* block still open while new block started */
  207.     HTML_CLOSE_BLOCK,            /* block closed but was never opened */
  208.     HTML_OPEN_ELEMENT,            /* unbalanced terminator */
  209.     HTML_NESTED,                /* improperly nested element */
  210.     HTML_VIOLATION,                /* bad content for current block/element */
  211.     HTML_NOTIFY,                /* insertion of optional opening/closing */
  212.     HTML_INTERNAL                /* internal parser error */
  213. }parserError;
  214.  
  215. /*****
  216. * And corresponding values for XmNenableBadHTMLWarnings.
  217. * These are or'd together.
  218. * XmNONE disables warnings and XmHTML_ALL enables all warnings.
  219. * See parserError for their meaning.
  220. *****/
  221. enum{
  222.     XmHTML_NONE = 0,                        /* no warnings */
  223.     XmHTML_UNKNOWN_ELEMENT = 1,    
  224.     XmHTML_BAD = 2,
  225.     XmHTML_OPEN_BLOCK = 4,
  226.     XmHTML_CLOSE_BLOCK = 8,
  227.     XmHTML_OPEN_ELEMENT = 16,
  228.     XmHTML_NESTED = 32,
  229.     XmHTML_VIOLATION = 64,
  230.     XmHTML_ALL = 128                /* all warnings */
  231. };
  232.  
  233. /*****
  234. * Definition of parsed HTML elements
  235. *****/
  236. typedef struct _XmHTMLObject{
  237.     htmlEnum     id;            /* ID for this element */
  238.     String        element;    /*
  239.                             * Raw text. For HTML elements, freeing this 
  240.                             * member also frees attributes.
  241.                             */
  242.     String         attributes;    /* attributes for this element, if any */
  243.     Boolean        ignore;        /* true if element must be ignored */
  244.     Boolean        is_end;        /* true when this is a closing element */
  245.     Boolean     terminated;    /* true when element has a closing counterpart */
  246.     Boolean        auto_insert;/* auto inserted element */
  247.     int         line;        /* line number for this element */
  248.     struct _XmHTMLObject *next;
  249.     struct _XmHTMLObject *prev;
  250. }XmHTMLObject;
  251.  
  252. /*****
  253. * Function to be called when the parser finished a single pass on the input
  254. *
  255. * ARGS:
  256. *   First : The current list of parser objects, which may NOT be freed.
  257. *   Second: True if input was HTML3.2 conforming, False if not;
  258. *   Third : True if parser verification succeeded;
  259. *   Fourth: True if parser tree was balanced;
  260. *   Fifth : current parser pass (count starts at 0);
  261. *   Sixth : length of input text;
  262. * Return values:
  263. *   True  : make another pass on the input using the current (possibly
  264. *           repaired) output;
  265. *   False : don't make another pass on the input;
  266. *****/
  267. typedef Boolean (*ParserDocumentCallback)(XmHTMLObject*, Boolean, Boolean,
  268.     Boolean, int, int);
  269. extern ParserDocumentCallback parser_document_callback;
  270.  
  271. /*****
  272. * Function to be called upon completion of a single pass
  273. * ARGS:
  274. *   First : number of elements still on stack (only when document is
  275. *           unbalanced);
  276. *   Second: number of (missing) HTML tags inserted by the parser;
  277. *   Third : number of HTML tags ignored by the parser;
  278. * Return values:
  279. *   None.
  280. *****/
  281. typedef void (*ParserAutoCorrectCallback)(int, int, int);
  282. extern ParserAutoCorrectCallback parser_autocorrect_callback;
  283.  
  284. /*****
  285. * Parser state stack object
  286. *****/
  287. typedef struct _stateStack{
  288.     htmlEnum id;                            /* current state id */
  289.     struct _stateStack *next;                /* ptr to next record */
  290. }stateStack;
  291.  
  292. /*****
  293. * A Parser
  294. *****/
  295. typedef struct _Parser{
  296.     String source;                /* text being parsed                    */
  297.     int index;                    /* last known position                    */
  298.     int len;                    /* length of input text                    */
  299.     int num_lines;                /* current line count                    */
  300.     Dimension line_len;            /* maximum line length so far            */
  301.     Dimension cnt;                /* current line length                    */
  302.  
  303.     /* running list of inserted elements */
  304.     int num_elements;            /* no of tags inserted so far            */
  305.     int num_text;                /* no of text elements inserted so far    */
  306.     XmHTMLObject *head;            /* head of object list                    */
  307.     XmHTMLObject *current;        /* lastly inserted element                */
  308.  
  309.     stateStack state_base;        /* stack base point                        */
  310.     stateStack *state_stack;    /* actual stack                            */
  311.  
  312.     int cstart;                    /* current element start position        */
  313.     int cend;                    /* current element end position            */
  314.  
  315.     Boolean strict_checking;    /* HTML 3.2 looseness flag                */
  316.     Boolean have_body;            /* indicates presence of <body> tag        */
  317.     Boolean warn;                /* warn about bad html constructs        */
  318.     Boolean bad_html;            /* bad HTML document flag                */
  319.     Boolean html32;                /* HTML32 conforming document flag        */
  320.     Boolean    automatic;            /* when in automatic mode                */
  321.  
  322.     Widget widget;                /* for the warning messages                */
  323. }Parser;
  324.  
  325. /*****
  326. * Various helper functions used by the parser (and defined by the parser
  327. * when it's compiled with -DMINIPARSE
  328. *****/
  329.  
  330. extern void my_locase(char *string);
  331. extern char* my_strcasestr(const char *s1, const char *s2);
  332. extern char* my_strndup(const char *s1, size_t len);
  333. extern char* my_strdup(const char *s1);
  334.  
  335. /*****
  336. * The parser uses strcasecmp and strncasecmp. Since these do not exist
  337. * on every system, the parser carriers fallback copies which will be used
  338. * if you define -DNEED_STRCASECMP at compile time.
  339. *****/
  340. #ifdef NEED_STRCASECMP
  341.  
  342. extern int my_strcasecmp (const char *s1, const char *s2);
  343. extern int my_strncasecmp (const char *s1, const char *s2, size_t n);
  344.  
  345. #define strcasecmp(S1,S2) my_strcasecmp(S1,S2)
  346. #define strncasecmp(S1,S2,N) my_strncasecmp(S1,S2,N)
  347.  
  348. #endif
  349.  
  350. /*****
  351. * Warning message display function
  352. * When parser_warnings has been set to False, no warnings will be
  353. * generated.
  354. *****/
  355. #define __WFUNC__(WIDGET_ID, FUNC)    (Widget)WIDGET_ID, __FILE__, \
  356.      __LINE__, FUNC
  357.  
  358. extern void __XmHTMLWarning(
  359. #ifdef __STDC__ 
  360.     Widget w, String module, int line, String routine,
  361.     String fmt, ...
  362. #endif
  363. );
  364.  
  365. #define _XmHTMLWarning __XmHTMLWarning
  366.  
  367. /*****
  368. * Public Parser Functions
  369. *****/
  370.  
  371. /*****
  372. * Write the list of objects to the given file. If notext is True, HTML
  373. * text segments will not be included in the output file.
  374. *****/
  375. extern void ParserWriteOutputToFile(XmHTMLObject *objects, String prefix,
  376.     Boolean notext);
  377.  
  378. /* Write the list of objects to the given file as a HTML file */
  379. extern void ParserWriteHTMLOutputToFile(XmHTMLObject *objects, String prefix,
  380.     Boolean notext);
  381.  
  382. /* compose a HTML output string from the list of objects */
  383. extern String _XmHTMLTextGetString(XmHTMLObject *objects);
  384.  
  385. /* free the given list of objects */
  386. extern void _XmHTMLFreeObjects(XmHTMLObject *objects);
  387.  
  388. /*****
  389. * The parser. Takes a two widgets, a previous list of objects and the text
  390. * to be parsed as it's input.
  391. * Returns a list of parsed objects.
  392. *****/
  393. extern XmHTMLObject *_XmHTMLparseHTML(XmHTMLWidget html,
  394.     XmHTMLObject *old_list, char *input, XmHTMLWidget dest);
  395.  
  396. /* Don't add anything after this endif! */
  397. #endif /* _miniparse_h_ */
  398.